package com.kanche.bigbaby.collection.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.kanche.bigbaby.R;
import com.kanche.bigbaby.collection.DateUtils;
import com.kanche.bigbaby.collection.StringUtils;

//import com.kkche.bss.R;
//import com.kkche.bss.utils.DateUtils;
//import com.kkche.bss.utils.StringUtils;

/**
 * Created by nealmi on 6/11/14.
 */
public class ItemDatePickerConfig extends ItemConfig {
    private int layoutId = R.layout.input_list_item_date_picker;
    private String hint;


    public ItemDatePickerConfig(String key, String value, String label, String caption) {
        super(key, value, label);
        setCaption(caption);
    }

    public String getHint() {
        return hint;
    }

    public void setHint(String hint) {
        this.hint = hint;
    }

    @Override
    public View getView(View convertView, Context mContext) {
        Holder holder = null;
        String canonicalName = ItemDatePickerConfig.class.getCanonicalName();
//        if (convertView != null)
//            holder = (Holder) convertView.getTag();
//        if (convertView == null || !canonicalName.equals(holder.type)) {
        holder = new Holder();

        LayoutInflater inflater = LayoutInflater.from(mContext);

        convertView = inflater.inflate(layoutId, null);

        holder.textView = (TextView) convertView.findViewById(R.id.textView);
        holder.caption = (TextView) convertView.findViewById(R.id.caption);
        holder.label = (TextView) convertView.findViewById(R.id.label);
        holder.type = canonicalName;
//            convertView.setTag(holder);
//        }

        holder.label.setText(getLabel());
        holder.caption.setText(getCaption());
        holder.textView.setHint(getHint());
        holder.textView.setText(DateUtils.formatToYearMonth(getValue()));
        if (StringUtils.hasText(getErrorMessage())) {
            holder.textView.setError(getErrorMessage());
        } else {
            holder.textView.setError(null);
        }
        return convertView;
    }

    class Holder {
        String type;
        TextView caption, label, textView;
    }

}
